package com.loriot.common.make_array_elements_equal_to_zero_3354;
public class Main {
    class Solution {
        public int countValidSelections(int[] nums) {
            // 从左到右移动标志位，计算当前标志位，左侧的和 与 右侧的和  的比较
            // 如果左侧的和与右侧的和相差==1，那么就+1，==0 就+2
            int rightSum = 0;
            for(Integer item:nums){
                rightSum+=item;
            }
            int leftSum = 0;
            int rst = 0;
            for(Integer item:nums){
                if(item==0){
                    if(rightSum==leftSum)rst+=2;
                    if(rightSum==leftSum+1||rightSum==leftSum-1)rst++;
                }else{
                    rightSum-=item;
                    leftSum+=item;
                }
            }
            return rst;
        }
    }
}
